Skip to content

Conversation

@mguetschow
Copy link
Contributor

Contribution description

While testing #21582, we found various issues in the current tinydtls sock_dtls implementation.

On master, tests/pkg/tinydtls_sock_async would throw an assertion failure on the second request from another instance of the same application (since the async session information is not reset). With the first commit, this does not happen anymore.

On master, examples/networking/coap/gcoap_dtls would print (with DEBUG enabled)

2025-10-29 16:42:31,018 # gcoap: could not establish DTLS session: 54
2025-10-29 16:42:33,291 # gcoap: could not establish DTLS session: 54
2025-10-29 16:42:34,259 # gcoap: could not establish DTLS session: 54
2025-10-29 16:42:35,046 # gcoap: no space in session management. We lost track of sessions!gcoap: could not establish DTLS session: 54

and not respond to any packages sent out by libcoap (with coap-client-gnutls "coaps://[<IP>%tap0]/.well-known/core" -k "secretPSK" -u "Client_identity" (presumably because the application data message is returned instead of the handshake completion signal). With the third commit of this PR, it works as expected.

The zero-copy sock_dtls_recv_buf APIs are currently untested by application code (gcoap uses copy-versions), but unicoap does use them. Applying #21582 (with some changes) on top of this PR shows that the fifth commit is needed for proper functioning.

The sixth commit removes unnecessary (and broken) logic which would send flags more than once. Those are not needed as the sock_async_event (and potential other backends should) accumulate(s) the flags internally already.

Testing procedure

Play around with tests/pkg/tinydtls_sock_async and examples/networking/coap/gcoap_dtls, or any other (your favorite) application using dtls_sock over tinydtls.

References

Some of the changes have already been discussed with @miri64 offline.

currently, sock_dtls_get_event_session would return a previous session instead of none as documented

fixes an assertion failure in tests/pkg/tinydtls_sock_async on a second request
@github-actions github-actions bot added the Area: pkg Area: External package ports label Oct 29, 2025
@crasbe crasbe added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Oct 29, 2025
@riot-ci
Copy link

riot-ci commented Oct 29, 2025

Murdock results

✔️ PASSED

59446cf sys/net/sock_dtls: document SOCK_DTLS_HANDSHAKE in user guide

Success Failures Total Runtime
10551 0 10552 11m:57s

Artifacts

miri64
miri64 previously requested changes Oct 29, 2025
Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly just some nits on documentation and commit messages.

Also, could you maybe in the testing instructions explicitly provide some of the things you did to "play around with the tests" (beyond the reproducing instructions in the summary), so I can test it myself. Thanks!

This way unconsumed application data is not overwritten.
also document that other messages are currently silently ignored from the mbox
They are not needed as the sock_async_event (and potential other backends should) accumulate(s) the flags internally already, and they have been sent out on data arrival or connection establishment already.
Copy link
Contributor Author

@mguetschow mguetschow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review, I was so brave to directly squash on force-push (to be able to edit the commit messages as requested).

@miri64
Copy link
Member

miri64 commented Nov 3, 2025

Currently no time for testing, so I leave that and the final ACK resulting from that to someone else :-)

Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm that this still works with coap-client-openssl and tests/net/nanocoap_cli

@benpicco benpicco added this pull request to the merge queue Nov 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: network Area: Networking Area: pkg Area: External package ports Area: sys Area: System CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants